const username =document.querySelector('#username')
const pwd=document.querySelector('#password')
const btn = document.querySelector('.btn')
const checkbox=document.querySelector('#check')
const  phone=document.querySelector('#phone')


btn.onclick=function (){

    if (checkbox.checked==false)
    {
        alert("勾选用户协议")
    }
    else
    {


        const xhr = new XMLHttpRequest()
        xhr.open('POST','http://8.130.14.155:8080/user/register','true')
        xhr.setRequestHeader('Content-Type','application/json')
        const params={
            username:username.value,
            password:pwd.value,
        }
        xhr.send(JSON.stringify(params))
        xhr.onreadystatechange=function (){
            if(xhr.readyState===4&&xhr.status===200){
                var result=JSON.parse(xhr.responseText)
                if (result.msg=='操作成功')
                {
                    alert("注册成功")
                location.href="login.html"
                }
                else {
                    alert(result.msg)
                    location.href="register.html"
                }
            }

        }
}
}